home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / misc / gms_dev.lha / GMSDev / Source / Asm / Demos / RainingBobs.s < prev    next >
Encoding:
Text File  |  1998-05-04  |  8.2 KB  |  346 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;This is a demonstration of raining bobs, which I use as a test routine to
  3. ;see how fast some of my blitter routines are.  It's a good example of using
  4. ;MBOB's, try out different MAX_IMAGES values to see how many you can get on
  5. ;screen.  **120** 16 colour 16x8 bobs just manage to run at full speed on my
  6. ;A1200+FAST, change the value if you have a faster machine (600 can be very
  7. ;interesting :-).
  8. ;
  9. ;Technical notes
  10. ;---------------
  11. ;This demo takes direct advantage of some special GMS blitting features,
  12. ;such as restorelist clearing without masks (gain: 10%), and 16 pixel
  13. ;alignment (gain: 15%).  That allows us to have 25% more BOB's on screen!
  14. ;
  15. ;The fact that GMS will use the CPU to draw and clear images when the blitter
  16. ;is busy gives a boost of about 20%+ on an '020, so the overall advantage
  17. ;over a bog standard blitting function (eg BltBitmap()) is at least 40%.
  18. ;Given that such a function would have to be called 120 times with newly
  19. ;calculated parameters each time to draw, and 120 times to do the clears, we
  20. ;are probably looking at least 65% faster... is that good enough?
  21.  
  22.     INCDIR    "INCLUDES:"
  23.     INCLUDE    "dpkernel/dpkernel.i"
  24.  
  25. MAX_IMAGES =    120
  26.  
  27.     SECTION    "Demo",CODE
  28.  
  29. ;===========================================================================;
  30. ;                             INITIALISE DEMO
  31. ;===========================================================================;
  32.  
  33.     STARTDPK
  34.  
  35. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  36.     move.l    DPKBase(pc),a6
  37.     lea    TAGS_BobsPicture(pc),a0
  38.     sub.l    a1,a1
  39.     CALL    Init
  40.     tst.l    d0
  41.     beq.s    .Exit
  42.  
  43.     move.l    PIC_Bobs(pc),a1
  44.     move.l    a1,RainPic
  45.     move.l    PIC_Bitmap(a1),a2
  46.     move.l    BMP_Palette(a2),GPalette
  47.  
  48.     lea    ScreenTags(pc),a0
  49.     sub.l    a1,a1
  50.     CALL    Init
  51.     move.l    d0,Screen
  52.     beq.s    .Exit
  53.  
  54.     lea    RestoreTags(pc),a0
  55.     move.l    Screen(pc),a1    ;a1 = Screen.
  56.     CALL    Init    ;>> = Initialise the restore list.
  57.     tst.l    d0    ;d0 = Check for errors.
  58.     beq.s    .Exit    ;>> = Error, exit.
  59.  
  60.     lea    TAGS_RainBob(pc),a0
  61.     move.l    Screen(pc),a1
  62.     move.l    GS_Bitmap(a1),a1
  63.     CALL    Init    ;>> = Initialise the Bob.
  64.     tst.l    d0
  65.     beq.s    .Exit
  66.  
  67.     moveq    #ID_JOYDATA,d0    ;Get joydata structure.
  68.     CALL    Get
  69.     move.l    d0,JoyData
  70.     beq.s    .Exit
  71.     move.l    d0,a0    ;Initialise the joydata structure.
  72.     sub.l    a1,a1
  73.     CALL    Init
  74.     tst.l    d0
  75.     beq.s    .Exit
  76.  
  77.     move.l    Screen(pc),a0
  78.     CALL    Display
  79.  
  80.     bsr.s    Main
  81.  
  82. .Exit    move.l    DPKBase(pc),a6
  83.     move.l    JoyData(pc),a0
  84.     CALL    Free
  85.     move.l    MBOB_Rain(pc),a0
  86.     CALL    Free
  87.     move.l    Restore(pc),a0
  88.     CALL    Free
  89.     move.l    Screen(pc),a0
  90.     CALL    Free
  91.     move.l    PIC_Bobs(pc),a0
  92.     CALL    Free
  93.     MOVEM.L    (SP)+,A0-A6/D1-D7
  94.     moveq    #ERR_OK,d0
  95.     rts
  96.  
  97. ;===========================================================================;
  98. ;                                DEMO CODE
  99. ;===========================================================================;
  100.  
  101. Main:    moveq    #$00,d7
  102.     move.l    MBOB_Rain(pc),a1
  103.  
  104.     move.l    Screen(pc),a0    ;a0 = Screen.
  105.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  106.     move.w    MB_AmtEntries(a1),d2
  107.     subq.w    #1,d2
  108. .create    bsr    RegenerateBob
  109.  
  110.     move.l    DPKBase(pc),a6
  111.     move.w    GS_Height(a0),d1
  112.     CALL    FastRandom
  113.     move.w    d0,BE_YCoord(a2)
  114.  
  115.     lea    NBE_SIZEOF(a2),a2
  116.     dbra    d2,.create
  117.  
  118. ;---------------------------------------------------------------------------;
  119. ;                                     MAIN LOOP
  120. ;---------------------------------------------------------------------------;
  121.  
  122. Loop:    move.l    Screen(pc),a0    ;a0 = Screen.
  123.     move.l    MBOB_Rain(pc),a1
  124.     addq.w    #1,d7
  125.     move.l    MB_EntryList(a1),a2    ;a2 = First entry.
  126.     move.w    MB_AmtEntries(a1),d2
  127.     subq.w    #1,d2
  128. .update    bsr.s    UpdateBob
  129.     lea    NBE_SIZEOF(a2),a2
  130.     dbra    d2,.update
  131.  
  132.     move.l    DPKBase(pc),a6
  133.     move.l    Restore(pc),a0
  134.     CALL    Activate
  135.  
  136.     move.l    MBOB_Rain(pc),a0    ;a0 = Bob to draw.
  137.     CALL    Draw    ;>> = Draw the mbob.
  138.  
  139.     move.l    SCRBase(pc),a6
  140.     CALL    scrWaitAVBL
  141.  
  142.     move.l    Screen(pc),a0
  143.     CALL    scrSwapBuffers
  144.  
  145.     move.l    DPKBase(pc),a6
  146.     move.l    JoyData(pc),a0
  147.     CALL    Query
  148.     move.l    JoyData(pc),a0
  149.     move.l    JD_Buttons(a0),d0
  150.     btst    #JB_LMB,d0
  151.     beq.s    Loop
  152.     rts
  153.  
  154. ;===========================================================================;
  155. ;                               UPDATE A BOB
  156. ;===========================================================================;
  157. ;Function: Moves the entity according to its internal settings.
  158. ;Requires: a1 = Bob structure.
  159. ;       a2 = Entry to update.
  160.  
  161. UpdateBob:
  162.     move.w    BE_YCoord(a2),d0    ;d0 = YCoord
  163.     add.w    BE_Speed(a2),d0    ;d0 = (YCoord)+YSpeed
  164.     cmp.w    GS_Height(a0),d0
  165.     blt.s    .YOkay
  166.     bsr    RegenerateBob
  167.     bra.s    .Animate
  168. .YOkay    move.w    d0,BE_YCoord(a2)
  169.  
  170. .Animate
  171.     tst.w    BE_Locked(a2)
  172.     beq.s    .exit
  173.     move.w    d7,d6
  174.     and.w    #%00000011,d6
  175.     bne.s    .exit
  176.     move.w    BE_FChange(a2),d1
  177.     bgt.s    .Positive
  178.  
  179. .Negative
  180.     cmp.w    #1,BE_Set(a2)
  181.     bgt.s    .NBlue
  182.     beq.s    .NGreen
  183. .NRed    add.w    d1,BE_Frame(a2)
  184.     tst    BE_Frame(a2)
  185.     bge.s    .exit
  186.     move.w    #1,BE_FChange(a2)
  187.     clr.w    BE_Frame(a2)
  188.     rts
  189. .NGreen    add.w    d1,BE_Frame(a2)
  190.     cmp.w    #4,BE_Frame(a2)
  191.     bge.s    .done
  192.     move.w    #1,BE_FChange(a2)
  193.     move.w    #4,BE_Frame(a2)
  194.     rts
  195. .NBlue    add.w    d1,BE_Frame(a2)
  196.     cmp.w    #8,BE_Frame(a2)
  197.     bge.s    .done
  198.     move.w    #1,BE_FChange(a2)
  199.     move.w    #8,BE_Frame(a2)
  200. .exit    rts
  201.  
  202. .Positive
  203.     cmp.w    #1,BE_Set(a2)
  204.     bgt.s    .PBlue
  205.     beq.s    .PGreen
  206. .PRed    add.w    d1,BE_Frame(a2)
  207.     cmp.w    #3,BE_Frame(a2)
  208.     ble.s    .done
  209.     move.w    #-1,BE_FChange(a2)
  210.     move.w    #2,BE_Frame(a2)
  211.     rts
  212. .PGreen    add.w    d1,BE_Frame(a2)
  213.     cmp.w    #7,BE_Frame(a2)
  214.     ble.s    .done
  215.     move.w    #-1,BE_FChange(a2)
  216.     move.w    #6,BE_Frame(a2)
  217.     rts
  218. .PBlue    add.w    d1,BE_Frame(a2)
  219.     cmp.w    #11,BE_Frame(a2)
  220.     ble.s    .done
  221.     move.w    #-1,BE_FChange(a2)
  222.     move.w    #10,BE_Frame(a2)
  223. .done    rts
  224.  
  225. ;===========================================================================;
  226. ;                            REGENERATE BOB ENTITY
  227. ;===========================================================================;
  228. ;Function: Regenerates an entity with completely new data.
  229. ;Requires: a2 = Entry to update.
  230.  
  231. RegenerateBob:
  232.     move.l    DPKBase(pc),a6
  233.     move.w    GS_Width(a0),d1
  234.     CALL    FastRandom
  235.     subq.w    #4,d0
  236.     and.w    #%1111111111111000,d0
  237.     move.w    d0,BE_XCoord(a2)
  238.  
  239.     moveq    #8,d1
  240.     CALL    FastRandom
  241.     addq.w    #2,d0
  242.     move.w    d0,BE_Speed(a2)
  243.  
  244.     moveq    #12,d1
  245.     CALL    FastRandom
  246.     move.w    d0,BE_Frame(a2)
  247.     move.b    .Sets(pc,d0.w),BE_Set+1(a2)
  248.  
  249.     move.w    #-8,BE_YCoord(a2)
  250.     move.w    #1,BE_FChange(a2)
  251.     eor.w    #1,BE_Locked(a2)
  252.     rts
  253.  
  254. .Sets    dc.b    0,0,0,0
  255.     dc.b    1,1,1,1
  256.     dc.b    2,2,2,2
  257.  
  258. ;===========================================================================;
  259. ;                                  DATA
  260. ;===========================================================================;
  261.  
  262. JoyData:    dc.l  0
  263.  
  264. RestoreTags:    dc.l  TAGS_RESTORE
  265. Restore:    dc.l  0
  266.         dc.l  RSA_Entries,MAX_IMAGES
  267.         dc.l  TAGEND
  268.  
  269. ;---------------------------------------------------------------------------;
  270.  
  271. ScreenTags:    dc.l  TAGS_SCREEN
  272. Screen:        dc.l  0
  273.         dc.l  GSA_Attrib,SCR_DBLBUFFER
  274.         dc.l    GSA_BitmapTags,0
  275.         dc.l    BMA_Palette
  276. GPalette:    dc.l    0
  277.         dc.l    TAGEND,0
  278.         dc.l  TAGEND
  279.  
  280. ;---------------------------------------------------------------------------;
  281.  
  282. TAGS_BobsPicture:
  283.         dc.l  TAGS_PICTURE
  284. PIC_Bobs:    dc.l  0
  285.         dc.l    PCA_BitmapTags,0
  286.         dc.l    BMA_MemType,MEM_VIDEO
  287.         dc.l    TAGEND,0
  288.         dc.l  PCA_Source,.filename
  289.         dc.l  TAGEND
  290.  
  291. .filename    FILENAME "GMS:demos/data/PIC.Pulse"
  292.  
  293. ;---------------------------------------------------------------------------;
  294.  
  295.   ;This is a mutated entrylist that we use for the raining bobs.
  296.  
  297.   STRUCTURE    NBE,BE_SIZEOF
  298.     WORD    BE_Speed    ;Speed of this particular bob.
  299.     WORD    BE_Set    ;0 = Red, 1 = Green, 2 = Blue.
  300.     WORD    BE_FChange
  301.     WORD    BE_Locked    ;Is it animated or not.
  302.     LABEL    NBE_SIZEOF
  303.  
  304. TAGS_RainBob:    dc.l  TAGS_MBOB
  305. MBOB_Rain:    dc.l  0
  306.         dc.l  MBA_AmtEntries,MAX_IMAGES
  307.         dc.l  MBA_GfxCoords,RainFrames
  308.         dc.l  MBA_Width,8
  309.         dc.l  MBA_Height,8
  310.         dc.l  MBA_EntryList,Images
  311.         dc.l  MBA_Attrib,BBF_CLIP|BBF_GENMASKS|BBF_CLEAR|BBF_CLRNOMASK
  312.         dc.l  MBA_Source
  313. RainPic:    dc.l  0
  314.         dc.l  MBA_EntrySize,NBE_SIZEOF
  315.         dc.l  TAGEND
  316.  
  317. RainFrames:    dc.w   0,8*0    ;RED
  318.         dc.w   0,8*1
  319.         dc.w   0,8*2
  320.         dc.w   0,8*3
  321.         dc.w   8,8*0    ;GREEN
  322.         dc.w   8,8*1
  323.         dc.w   8,8*2
  324.         dc.w   8,8*3
  325.         dc.w  16,8*0    ;BLUE
  326.         dc.w  16,8*1
  327.         dc.w  16,8*2
  328.         dc.w  16,8*3
  329.         dc.l  -1
  330.  
  331. ;---------------------------------------------------------------------------;
  332.  
  333.     SECTION    Images,BSS
  334.  
  335. Images:    ds.b    NBE_SIZEOF*MAX_IMAGES    ;X/Y/Frame/Speed/Set/FChange/Locked
  336.  
  337. ;===========================================================================;
  338.  
  339. ProgName:    dc.b  "Raining Bobs",0
  340. ProgAuthor:    dc.b  "Paul Manias",0
  341. ProgDate:    dc.b  "May 1998",0
  342. ProgCopyright:    dc.b  "DreamWorld Productions (c) 1996-1998.  Freely distributable.",0
  343. ProgShort:    dc.b  "Multiple bobs demonstration.",0
  344.         even
  345.  
  346.